package com.block.api.controller.im;

import com.alibaba.fastjson.JSONObject;
import com.block.common.annotate.NeedToken;
import com.block.common.bean.CommonParam;
import com.block.common.bean.SessionBean;
import com.block.common.exception.ApiException;
import com.block.common.security.util.ApiUtil;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import com.block.im.service.IImUserCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("api/im")
@Validated
public class ImController {

    @Autowired
    IImUserCommonService imUserCommonService;

    /**+
     * im 用户登陆
     */
    @NeedToken
    @RequestMapping(value = "/loginIn", method = {RequestMethod.POST, RequestMethod.GET})
    public String loginIn(@RequestAttribute(value = "tranData") JSONObject tranData,
                          @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                          @RequestAttribute(value = "uri") String uri,
                          @RequestAttribute(value = "commonParam") CommonParam commonParam,
                          @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                          @RequestAttribute(value = "startDate") Date startdate,
                          @RequestAttribute(value = "ip") String ip) throws ApiException {

        Boolean flushFlag = tranData.getBoolean("flushFlag");

        ResponseVo responseVo = imUserCommonService.getMemberImUser(sessionBean.getUid(), flushFlag);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt, startdate, uri);
    }


}
